// FloatingTextManager class
// This class manages floating text that pops up
// in the middle of the game (text rendered in 
// world coordinates
#pragma once

#include "d3dUtil.h"
#include "View.h"
#include "FloatingTextTypes.h"

#define TEXT_BUFFERSIZE 128

#define TEXTMANAGER	FloatingTextManager::Instance()

struct TextData
{
	int					id;			// id number for persistent text objects
	bool				threeD;		// if the text coordinate needs to be converted from real to screen coordinates
	FloatingTextType	textType;	// type of text (floating, bouncing etc)
	char				*text;		// text string to render
	float				maxLifeTime;	// total life of the text
	float				lifeTime;		// current life of the text
	float				minScale;		// minimum scale for growing/shrinking text
	float				maxScale;		// maximum scale for growing/shrinking text
	float				scale;			// current scale (only only scale for non-growing/shrinking text)
	D3DXVECTOR3			position;		// position of the text, could be 2D or 3D. use the 'threeD' parameter to enable 3D mode
	D3DXVECTOR3			realposition;	// used to convert from real coords to screen coords
	D3DXVECTOR3			velocity;		// velocity of moving text
	ID3DXFont			*font;			// font object to use
	D3DCOLOR			color;			// color to render
	float				delay;			// time until the message begins rendering
};

class FloatingTextManager
{
private:
	// private constructors
	FloatingTextManager(void);
	FloatingTextManager(const FloatingTextManager&);
	FloatingTextManager* operator=(const FloatingTextManager&);
	~FloatingTextManager(void);

protected:
	// storage of mesh and buffer information
	typedef std::vector<TextData*> Texts;
	Texts textData;

	ID3DXSprite *mSprite;

	float mBBHeight;
	float mBBWidth;

	unsigned int mNextPersistentTextID;

public:
	// converts the given position in 3D space into screen coordinates
	D3DXVECTOR3 ConvertToScreenCoords(D3DXVECTOR3 position);

	void OnResetDevice(int bbwidth, int bbheight);
	void OnLostDevice(void);

	// initialize the text manager by giving
	// it a sprite to draw with
	void Initialize(void);

	// updates all text objects
	void Update(float dt);

	// renders all text objects to the screen
	void Render();

	// adds a new text object to the list
	void AddBouncingText(ID3DXFont *font, bool threeD, char* text, float lifeTime, D3DXVECTOR3 position, float minScale, float maxScale, D3DCOLOR color, float delay = 0);

	// returns the id number of this persistent text object
	int AddPersistentText(ID3DXFont *font, bool threeD, char* text, D3DXVECTOR3 position, D3DCOLOR color, float delay = 0);

	void AddRisingText(ID3DXFont *font, bool threeD, char* text, float lifeTime, float scale, D3DXVECTOR3 startPos, D3DXVECTOR3 velocity, D3DCOLOR color, float delay = 0);

	// creates a text buffer
	char* CreateTextBuffer(char* text);

	// draws text at the given location at this instant, rather than relying on a persistent text object
	void DrawInstantText(ID3DXFont *font, bool threeD, char* text, float scale, D3DXVECTOR3 position, D3DCOLOR color);

	// disables persistent text with the given ID
	void DisablePersistentText(unsigned int id);
	
	// accessing the singleton
	static FloatingTextManager* Instance();

	// adds a new text object to draw
};